package com.example.rumen;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class adapter extends AppCompatActivity {

    String items[] = new String[]{"大数据","机器学习","人工智能","智能算法","机器视觉","机器人","智能家居","智能机器人"};

    private ListView list_view;
    private ArrayAdapter<String> arrayAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_adapter);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        //1.准备框架
        list_view = findViewById(R.id.listview);
        //2.准备布局文件
        arrayAdapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.adapter,items);
        //3.准备数据
        //4.实现数组适配器
        //5.加载适配器
        list_view.setAdapter(arrayAdapter);
        //6.实现单击事件

        list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Toast.makeText(getApplicationContext(),"您当前选择的是"+items[position],Toast.LENGTH_SHORT).show();


            }
        });
    }
}